//
//  SDSectionViewController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/8/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDSectionViewController.h"
#import "SDFamousDoctorsView.h"
#import "SDSubdivideViewController.h"
#import "SDFocusDoctorController.h"


@interface SDSectionViewController ()

@property (nonatomic, strong) SDFamousDoctorsView *vw_doctorView;

@end

@implementation SDSectionViewController

- (void)viewDidLoad{
    
    [super viewDidLoad];
    [self setupUI];
    [self setupLayout];
    [self setupSubviewBlock];
}

- (void)setupUI{
    
    self.navigationItem.title = self.titleName;
    self.view.backgroundColor = [UIColor colorWithRed:236.0/255 green:236.0/255 blue:236.0/255 alpha:1.0];
    self.automaticallyAdjustsScrollViewInsets = NO;
}
- (void)setupLayout{
    
    [self.vw_doctorView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom);
        make.leading.bottom.trailing.mas_equalTo(0);
        
    }];
}

#pragma mark
#pragma mark - 到指定的talbe
- (void)setupSubviewBlock{
    
    //MARK：名医通跳转界面
    __weak typeof(self) weakSelf = self;
    self.vw_doctorView.pushOtherBlock = ^(SDPatientType patientType, NSString *name){
        SDSubdivideViewController *vc = [[SDSubdivideViewController alloc] init];
        vc.patientType = patientType;
        vc.titleName = name;
        
        //从名益通界面返回到本界面
        vc.famousDoctorsBlock = ^(NSMutableArray *disease, SDPatientType patientType){
            NSMutableString *strM = [NSMutableString string];
            
            if (disease.count == 1) {
                [strM appendString:disease.firstObject];
            }else{
                [disease enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if (idx == 0) {
                        [strM appendString:obj];
                    }else{
                        [strM appendFormat:@"、%@",obj];
                    }
                }];
            }
            
            [weakSelf.vw_doctorView setDiseaseType:strM.copy forStyle:patientType];
        };
        
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    
    self.vw_doctorView.pushFocusDoctorBlock =  ^{
        SDFocusDoctorController *vc = [[SDFocusDoctorController alloc] init];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
}

#pragma mark
#pragma mark - 懒加载子控件
- (SDFamousDoctorsView *)vw_doctorView{
    if (_vw_doctorView == nil) {
        
        _vw_doctorView = [[SDFamousDoctorsView alloc] init];
        [_vw_doctorView setUserName:@"李神医" withTypeName:self.titleName withDoctors:30];
        [self.view addSubview:_vw_doctorView];
    }
    return _vw_doctorView;
}

@end
